package br.com.galante.webapp.view;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.component.submenu.Submenu;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;

@Named("menu")
@SessionScoped
public class MenuView extends BaseView implements Serializable{

	private static final long serialVersionUID = -8929815894096587925L;
	
//	@Inject
//	private Authenticator authenticator = new Authenticator();
	
	private MenuModel model;

	public MenuView() {
		createMenu();
	}
	
	private void createMenu(){
		model = new DefaultMenuModel();
		
		//Admin submenu
		Submenu submenu1 = new Submenu();
		
		Submenu submenu2 = new Submenu();
		submenu2.setLabel("Dynamic Submenu 1");
		
		MenuItem item = new MenuItem();
		item.setValue("Administrador");
		item.setUrl("/private/admin/home.jsf");
		submenu2.getChildren().add(item);
		submenu1.getChildren().add(submenu2);
		
//		if (authenticator.isUserInRole(Authenticator.ADMIN_ROLE))
			model.addSubmenu(submenu2);
		
		//User submenu
		item = new MenuItem();
		item.setValue("Usuário");
		item.setUrl("/private/user/home.jsf");
		
//		if (authenticator.isUserInRole(Authenticator.USER_ROLE))
			model.addMenuItem(item);
		
		
		//Public submenu
		item = new MenuItem();
		item.setValue("Home");
		item.setUrl("/home.jsf");
		
		model.addMenuItem(item);
	}

	public MenuModel getModel() {
		model = null;
		if (model == null)
			createMenu();
		return model;
	}	
	
}
